package com.ym.b2b.dictionary.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ym.b2b.commons.exception.BaseException;
import com.ym.b2b.commons.service.BaseService;
import com.ym.b2b.dictionary.dao.EmSDictionaryDAO;
import com.ym.b2b.dictionary.service.EmSDictionaryService;
import com.ym.b2b.dictionary.sqlbean.EmSDictionary;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;

@Service
public class EmSDictionaryServiceImpl extends BaseService implements EmSDictionaryService {

    @Autowired
    private EmSDictionaryDAO dictionaryDao;

    @Override
    public Result searchPageEmSDictionary(EmSDictionary emSDictionary, Page<EmSDictionary> page) {
        // TODO Auto-generated method stub
        Result result = new Result();
        try {
            result.setResultPage(dictionaryDao.searchPageEmSDictionary(emSDictionary, page));
        } catch (Exception e) {
            throw new BaseException(Result.CODE_100, "查询异常");
        }
        return result;
    }

    @Override
    public int deleteEmSDictionary(Long dictionaryId) {
        int result = dictionaryDao.deleteEmSDictionary(dictionaryId);
        return result;
    }

    @Override
    public int deleteMultipleEmSDictionary(String ditionaryIdList) {
        int rows = dictionaryDao.deleteMultipleEmSDictionary(ditionaryIdList);
        return rows;

    }

    @Override
    public Result updateEmSDictionary(EmSDictionary emSDictionary) {
        Result result = new Result();
        try {
            dictionaryDao.updateEmSDictionary(emSDictionary);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public Result updateEmSDictionaryBat(EmSDictionary emSDictionary) {
        Result result = new Result();
        try {
            dictionaryDao.updateEmSDictionaryBat(emSDictionary);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public Result searchEmSDictionary(EmSDictionary emSDictionary) {
        Result result = new Result();
        EmSDictionary dictionary = new EmSDictionary();
        try {
            dictionary = dictionaryDao.searchEmSDictionary(emSDictionary.getDictionaryId());
            result.putData("dictionary", dictionary);
            result.setResult("查询信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "查询信息失败!");
        }
        return result;
    }

    @Transactional
    @Override
    public Result insertEmSDictionary(EmSDictionary emSDictionary) {
        Result result = new Result();
        try {
            dictionaryDao.insertEmSDictionary(emSDictionary);
            result.setResult("添加信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "添加信息失败!");
        }
        return result;
    }

}
